﻿Imports Fu3DEngine
Imports DrawContour
Imports System.IO

Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary



Public Class frmVtkRender



    Private Sub frmVtkRender_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '设置网格和坐标不可见
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisLine.AxisVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisLabel.LabelVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisTitle.TitleVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.LeftAxis.AxisGridding.AxisGriddingVisible = False

        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisLine.AxisVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisLabel.LabelVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisTitle.TitleVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.BottomAxis.AxisGridding.AxisGriddingVisible = False

        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.TopAxis.AxisLine.AxisVisible = False
        Me.ContourPaintForm1.ContourPaintSetting.ContourPannel.Axes.RightAxis.AxisLine.AxisVisible = False

        '引擎场景初始化



        If FuEngine.GetEngine.GetScene("terrainscene") IsNot Nothing Then

            FuEngine.GetEngine.GetScene("terrainscene").InitScene(renderWindowControl1)

            FuEngine.GetEngine.RestoreSceneToTree()



        Else

            FuEngine.GetEngine().InitEngine()
            Dim ts As New TerrainScene("terrainscene")
            ts.desc = "地形场景"
            ts.InitScene(renderWindowControl1)

            FuEngine.GetEngine().AddScene(ts)


            ' FuEngine.GetEngine().Run()



        End If

       














    End Sub

    Public Sub SaveScene(ByVal strfile As String)

        Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").SaveSceneBinary(strfile)

    End Sub

    Public Sub OpenScene(ByVal strfile As String)

        Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").LoadSceneBinary(strfile)

    End Sub


    Private Sub frmVtkRender_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        '关闭当前场景，使停止引擎

        '保存对应的文档
        If m_Ready Then

            If Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene") IsNot Nothing Then



                Dim nameProj As String = fPath + "vtk.fzh"
                Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").SaveSceneBinary(nameProj)

            End If



        End If

        Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").ClearScene()

       





    End Sub

    ''' <summary>
    ''' 主要作用，是判断本窗口是否是第一次调用changesource
    ''' </summary>
    ''' <remarks></remarks>
    Dim m_Ready As Boolean = False

    Dim xPre, yPre As Double




    Public Sub ChangeSource(ByVal isDem As Boolean, ByVal demFile As String, ByVal rect As CAermod.RectArea, ByVal proj As CAermod.ProjSet)

        '建立对应的场景



        '判断方案是否 已经存在，如果不存在就创建，存在就加载
        ' Dim bExist As Boolean = False
        Dim nameProj As String = fPath + "vtk.fzh"




        '保存旧有的方案,目前是在setproj中保存的





        FuEngine.GetEngine.GetScene("terrainscene").ClearScene()











        '先计算偏移量
        Dim recept As CAermod.Receptor = proj.TempAermod.Receptor
        Dim xRel, yRel As Double
        xRel = recept.SubGridCart(0).Xinit
        yRel = recept.SubGridCart(0).Yinit

        '定义对应的绝对和便宜坐标
        Dim xAbs, yAbs As Double
        xAbs = AermodProject0.GetLeftButtomUtmXY().x
        yAbs = AermodProject0.GetLeftButtomUtmXY().y


        xPre = xAbs - xRel
        yPre = yAbs - yRel




        '这里已经成功的求出了偏移量




        '前面直接加载为啥不行咧，有个bug，需要调试一下，所以这里有点麻烦

        '当三维引擎已经有对应的保存的时候，就好说啦，加载之，没有就只能继续写了
        If File.Exists(nameProj) Then

            '下面的语句，只是为了解决一个软件bug,第一次启动窗口的时候，需要用到
            If m_Ready = False Then

            Else


                '能加载的话，就加载好了
                FuEngine.GetEngine.GetScene("terrainscene").LoadSceneBinary(nameProj)

                Return


            End If



        Else


        End If






        '然后分别算出主网格的对角坐标
        Dim enPtX, enPtY As Double
        enPtX = xAbs + recept.SubGridCart(0).Xdelta * (recept.SubGridCart(0).Xnum - 1)
        enPtY = yAbs + recept.SubGridCart(0).Ydelta * (recept.SubGridCart(0).Ynum - 1)








        '靠，忘记边界是绝对还是相对的了，先按绝对算

        Dim tii As TerrainInitInfo

        If isDem Then

            tii = New TerrainInitInfo(demFile)

        Else

            tii = New TerrainInitInfo(rect.Xmin + xPre, rect.Ymin + yPre, rect.Xmax + xPre, rect.Ymax + yPre)

        End If






        Dim cn As New ConcentrationNodeV3("concentration")


        Dim ti As TerrainInfo

        ti = cn.InitTerrain(tii)

        cn.SetTextureCoord(xAbs, yAbs, enPtX, enPtY)



        cn.desc = "浓度等值线图"
        'cn.MyContours = cons

        Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").AddNode(cn)

        '这里调用有意义的坐标，才能够起作用,这里是主网格的对角，绝对值坐标




        '开始添加对应的污染源




        Me.AddSource(proj, ti)





        Fu3DEngine.FuEngine.GetEngine().Run()





        '前面直接加载为啥不行咧，有个bug，需要调试一下，所以这里有点麻烦

        '当三维引擎已经有对应的保存的时候，就好说啦，加载之，没有就只能继续写了
        If File.Exists(nameProj) Then

            '下面的语句，只是为了解决一个软件bug,第一次启动窗口的时候，需要用到
            If m_Ready = False Then


                '能加载的话，就加载好了
                FuEngine.GetEngine.GetScene("terrainscene").LoadSceneBinary(nameProj)






            Else


            End If



        Else


        End If








        'Me.renderWindowControl1.RenderWindow.GetRenderers.GetFirstRenderer.ResetCamera()

        m_Ready = True


    End Sub






    Protected Function GetXAbs(ByVal x As Double) As Double

        Return x + xPre


    End Function

    Protected Function GetYAbs(ByVal y As Double) As Double

        Return y + yPre

    End Function



    Protected Sub AddSource(ByVal m_proj As CAermod.ProjSet, ByVal ti As TerrainInfo)



        '    Case "cpoint" '关心点


        Dim layerConcern As New Layer("concernpoint")
        layerConcern.desc = "关心点"
        layerConcern.AmbientColor = Color.Yellow

        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerConcern)

        For i As Integer = 0 To m_proj.TempAermod.Receptor.DiscCarts.Length - 1


            Dim x, y, r, h, hg As Double
            x = Me.GetXAbs(m_proj.TempAermod.Receptor.DiscCarts(i).Xcoord)
            y = Me.GetYAbs(m_proj.TempAermod.Receptor.DiscCarts(i).Ycoord)

            r = 10



            hg = m_proj.TempAermod.Receptor.DiscCarts(i).Zflag



            Dim sphere As New CPSphere(ti, x, y, r, hg)
            Dim spNode As New SphereNode(sphere, m_proj.TempAermod.Receptor.DiscCarts(i).ID)
            spNode.desc = m_proj.TempAermod.Receptor.DiscCarts(i).Name




            layerConcern.Add(spNode)

        Next



        ' Case "ppoint" 点源

        Dim layerPPoint As New Layer("pointsource")
        layerPPoint.AmbientColor = Color.Brown
        layerPPoint.desc = "点源"

        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerPPoint)



        For i As Integer = 0 To m_proj.TempAermod.Source.PointSources.PointSource.Length - 1


            Dim x, y, r, h As Double

            x = Me.GetXAbs(m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Xs)
            y = Me.GetYAbs(m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Ys)

            r = m_proj.TempAermod.Source.PointSources.PointSource(i).Stkdia / 2

            h = m_proj.TempAermod.Source.PointSources.PointSource(i).Stkhgt



            Dim cp As New CPCylinder(ti, x, y, r, h, 0)
            Dim cpnode As New CylinderNode(cp, m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Srcid)
            cpnode.desc = m_proj.TempAermod.Source.PointSources.PointSource(i).SourceName

            layerPPoint.Add(cpnode)

        Next




        'Case "pline" '线源

        Dim layerLine As New Layer("linesource")

        layerLine.desc = "线源."
        layerLine.AmbientColor = Color.Coral
        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerLine)


        For i As Integer = 0 To m_proj.TempAermod.Source.LineSources.ArrayLineSources.Length - 1




            '声明一个数组啊

            Dim dps(m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints.Length - 1) As DPoint

            Dim x, y As Double

            For j As Integer = 0 To m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints.Length - 1

                x = Me.GetXAbs(m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).x)

                y = Me.GetYAbs(m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).y)



                '关于数组，哈哈
                Dim dp As New DPoint(x, y)

                dps(j) = dp


            Next

            Dim w As Double = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).Width

            Dim hg As Double = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).Relhgt

            '半径，和高度，都没有定义哇

            Dim pl As New CPTubeLine(ti, w, 4, dps, hg)

            Dim tln As New TubeLineNode(pl, m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).Location.Srcid)
            tln.desc = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).SourceName

            layerLine.Add(tln)






        Next



        'Case "poly" '多边形

        Dim layerPoly As New Layer("polysource")
        layerPoly.desc = "多边形源"


        layerPoly.AmbientColor = Color.Crimson



        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerPoly)



        For i As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource.Length - 1


            '彻底崩溃，第一个点存的是相对坐标，其余点存的是绝对坐标，还有的都存了，有的没有存，让我彻底失败！


            Dim dps(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length) As DPoint

            Dim dp1 As New DPoint(Me.GetXAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Xs), Me.GetYAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Ys))
            dps(0) = dp1


            Dim x, y As Double

            For j As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length - 1

                x = Me.GetXAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).X)

                y = Me.GetYAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).Y)



                '关于数组，哈哈
                Dim dp As New DPoint(x, y)

                dps(j + 1) = dp



            Next




            'For i As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource.Length - 1




            '    Dim dps(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length - 1) As DPoint

            '    Dim x, y As Double

            '    For j As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length - 1

            '        x = Me.GetXAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).X)

            '        y = Me.GetYAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).Y)



            '        '关于数组，哈哈
            '        Dim dp As New DPoint(x, y)

            '        dps(j) = dp



            '    Next


            Dim hg As Double = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Relhgt
            Dim hd As Double = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Szinit
            If hd < 1 Then
                hd = 1
            End If


            Dim ply As New CPPoly(ti, hd, dps, hg)

            Dim plyNode As New PolygonNode(ply, m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Srcid)
            plyNode.desc = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).SourceName

            layerPoly.Add(plyNode)


        Next

        'Case "cube" '体源

        Dim layerCube As New Layer("cubesource")
        layerCube.desc = "体源"
        layerCube.AmbientColor = Color.DarkRed


        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerCube)


        For i As Integer = 0 To m_proj.TempAermod.Source.VolumeSources.VolumeSource.Length - 1




            Dim ps As CAermod.VolumeSources

            ps = m_proj.TempAermod.Source.VolumeSources

            Dim x, y, dx, dy, dz As Double

            x = Me.GetXAbs(ps.VolumeSource(i).Location.Xs)
            y = Me.GetYAbs(ps.VolumeSource(i).Location.Ys)


            dx = ps.VolumeSource(i).Width
            dy = ps.VolumeSource(i).Width
            dz = ps.VolumeSource(i).Height

            If dz < 1 Then
                dz = 1
            End If

            Dim hg As Double = ps.VolumeSource(i).Relhgt


            Dim cube As New CPCube(ti, x, y, dx, dy, dz, hg)
            Dim cubeNode As New CubeNode(cube, m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Srcid)
            cubeNode.desc = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).SourceName


            layerCube.Add(cubeNode)


        Next



        'Case "circle" '圆形面源

        Dim layerCircle As New Layer("circlesource")
        layerCircle.desc = "圆形面源"
        layerCircle.AmbientColor = Color.Aquamarine


        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerCircle)


        For i As Integer = 0 To m_proj.TempAermod.Source.AreacircSources.AreaCircSource.Length - 1


            Dim x, y, r, h
            x = Me.GetXAbs(m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Xs)
            y = Me.GetYAbs(m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Ys)

            r = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Radius

            h = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Szinit

            If h < 1 Then
                h = 1
            End If

            Dim hg As Double = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Relhgt '这里暂时理解面是没有高度的


            Dim cylinder As New CPCylinder(ti, x, y, r, h, hg)
            Dim cylinderNode As New CylinderNode(cylinder, m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Srcid)
            cylinderNode.desc = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).SourceName

            layerCircle.Add(cylinderNode)

        Next




        'Case "rect" '矩形面源

        Dim layerRect As New Layer("rectsource")
        layerRect.desc = "矩形面源"
        layerRect.AmbientColor = Color.AliceBlue

        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerRect)


        For i As Integer = 0 To m_proj.TempAermod.Source.AreaSources.AreaSource.Length - 1



            ''设置第一个点
            'Dim ptA(3) As MapWinGIS.Point
            'ptA(0) = New MapWinGIS.Point
            'ptA(0).x = Me.GetUtmFromRelative(m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Xs, m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys).x
            'ptA(0).y = Me.GetUtmFromRelative(m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Xs, m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys).y
            ''设置第2个点
            'ptA(1) = New MapWinGIS.Point
            'ptA(1).y = ptA(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
            'ptA(1).x = ptA(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
            ''设置第4个点
            'ptA(3) = New MapWinGIS.Point
            'ptA(3).y = ptA(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)
            'ptA(3).x = ptA(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)

            ''设置第3个点
            'ptA(2) = New MapWinGIS.Point
            'ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
            'ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x
            'fe.ptlist = ptA



            Dim temp As Double = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys

            Dim dps(3) As DPoint

            dps(0) = New DPoint(Me.GetXAbs(m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Xs), Me.GetYAbs(m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys))

            dps(1) = New DPoint()
            dps(1).y = dps(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
            dps(1).x = dps(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)



            dps(3) = New DPoint()
            dps(3).y = dps(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)
            dps(3).x = dps(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)


            dps(2) = New DPoint()
            dps(2).y = (dps(1).y - dps(0).y) + dps(3).y
            dps(2).x = (dps(1).x - dps(0).x) + dps(3).x







            Dim h As Double = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Szinit
            If h < 1 Then
                h = 1
            End If

            Dim hg As Double = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Relhgt

            Dim rect As New CPPoly(ti, h, dps, hg)
            Dim rectNode As New PolygonNode(rect, m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Srcid)
            rectNode.desc = m_proj.TempAermod.Source.AreaSources.AreaSource(i).SourceName


            layerRect.Add(rectNode)


        Next




        'Case "exp" '敞口源

        Dim layerExp As New Layer("expsource")
        layerExp.desc = "敞口源"
        layerExp.AmbientColor = Color.DarkOrange

        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerExp)

        For i As Integer = 0 To m_proj.TempAermod.Source.OpenPitSources.OpenPitSource.Length - 1




            'fe.desc = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).SourceName
            'fe.sn = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid
            ''设置第一个点
            'Dim ptA(3) As MapWinGIS.Point
            'ptA(0) = New MapWinGIS.Point
            'ptA(0).x = Me.GetUtmFromRelative(m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs, m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys).x
            'ptA(0).y = Me.GetUtmFromRelative(m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs, m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys).y
            ''设置第2个点
            'ptA(1) = New MapWinGIS.Point
            'ptA(1).y = ptA(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
            'ptA(1).x = ptA(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
            ''设置第4个点
            'ptA(3) = New MapWinGIS.Point
            'ptA(3).y = ptA(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)
            'ptA(3).x = ptA(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)

            ''设置第3个点
            'ptA(2) = New MapWinGIS.Point
            'ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
            'ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x



            Dim dps(3) As DPoint

            dps(0) = New DPoint(Me.GetXAbs(m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs), Me.GetYAbs(m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys))

            dps(1) = New DPoint()
            dps(1).x = dps(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
            dps(1).y = dps(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)

            dps(3) = New DPoint()
            dps(3).y = dps(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)
            dps(3).x = dps(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)

            dps(2) = New DPoint()
            dps(2).y = (dps(1).y - dps(0).y) + dps(3).y
            dps(2).x = (dps(1).x - dps(0).x) + dps(3).x




            Dim hg As Double = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Relhgt

            Dim h As Double = 1



            Dim rect As New CPPoly(ti, h, dps, hg)
            Dim rectNode As New PolygonNode(rect, m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid)
            rectNode.desc = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).SourceName

            layerExp.Add(rectNode)




        Next


        'Case "build" '建筑物


        Dim layerBuild As New Layer("building")

        layerBuild.desc = "建筑物"
        layerBuild.AmbientColor = Color.BlanchedAlmond

        FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerBuild)


        For i As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi.Length - 1


            'fe.desc = m_proj.TempAermod.Bprm.ArryBldgi(i).BuildName
            'fe.sn = m_proj.TempAermod.Bprm.ArryBldgi(i).BuildStack
            ''设置第一个点
            'Dim ptA(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1) As MapWinGIS.Point
            'For j As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1
            '    ptA(j) = New MapWinGIS.Point
            '    ptA(j).x = Me.GetUtmFromRelative(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x, m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y).x
            '    ptA(j).y = Me.GetUtmFromRelative(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x, m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y).y

            'Next



            Dim dps(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1) As DPoint

            For j As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1

                Dim dp As New DPoint()

                dp.x = Me.GetXAbs(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x)
                dp.y = Me.GetYAbs(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y)

                dps(j) = dp

            Next

            Dim h As Double = m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).TireHight
            Dim hg As Double = 0

            Dim build As New CPPoly(ti, h, dps, hg)
            Dim buildNode As New PolygonNode(build, m_proj.TempAermod.Bprm.ArryBldgi(i).BuildStack)
            buildNode.desc = m_proj.TempAermod.Bprm.ArryBldgi(i).BuildName


            layerBuild.Add(buildNode)


        Next








    End Sub



    'Protected Sub AddSource(ByVal m_proj As CAermod.ProjSet, ByVal ti As TerrainInfo)



    '    '    Case "cpoint" '关心点


    '    Dim layerConcern As New Layer("concernpoint")
    '    layerConcern.desc = "关心点"
    '    layerConcern.AmbientColor = Color.YellowGreen

    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerConcern)

    '    For i As Integer = 0 To m_proj.TempAermod.Receptor.DiscCarts.Length - 1


    '        Dim x, y, r, h As Double
    '        x = Me.GetXAbs(m_proj.TempAermod.Receptor.DiscCarts(i).Xcoord)
    '        y = Me.GetYAbs(m_proj.TempAermod.Receptor.DiscCarts(i).Ycoord)

    '        '关心点，没有高度的定义，这里只是一个默认值



    '        r = 5
    '        'h = 100


    '        'r = m_proj.TempAermod.Receptor.DiscCarts(i).Zelev

    '        'h = m_proj.TempAermod.Receptor.DiscCarts(i).Zelev



    '        Dim sphere As New CPSphere(ti, x, y, 5, 0)
    '        Dim spNode As New SphereNode(sphere, m_proj.TempAermod.Receptor.DiscCarts(i).ID)
    '        spNode.desc = m_proj.TempAermod.Receptor.DiscCarts(i).Name

    '        layerConcern.Add(spNode)

    '        'CPCylinder cp = new CPCylinder(ti, 412579, 137800, 50, 1000);
    '        'Dim cp As New CPCylinder(ti, x, y, r, h)
    '        'Dim cpnode As New CylinderNode(cp, m_proj.TempAermod.Receptor.DiscCarts(i).ID)
    '        'cpnode.desc = m_proj.TempAermod.Receptor.DiscCarts(i).Name

    '        'layerConcern.Add(cpnode)

    '    Next



    '    ' Case "ppoint" 点源

    '    Dim layerPPoint As New Layer("pointsource")
    '    layerPPoint.AmbientColor = Color.Blue

    '    layerPPoint.desc = "点源"

    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerPPoint)



    '    For i As Integer = 0 To m_proj.TempAermod.Source.PointSources.PointSource.Length - 1


    '        Dim x, y, r, h As Double

    '        x = Me.GetXAbs(m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Xs)
    '        y = Me.GetYAbs(m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Ys)

    '        r = m_proj.TempAermod.Source.PointSources.PointSource(i).Stkdia / 2

    '        h = m_proj.TempAermod.Source.PointSources.PointSource(i).Stkhgt



    '        Dim cp As New CPCylinder(ti, x, y, r, h, 0)
    '        Dim cpnode As New CylinderNode(cp, m_proj.TempAermod.Source.PointSources.PointSource(i).Location.Srcid)
    '        cpnode.desc = m_proj.TempAermod.Source.PointSources.PointSource(i).SourceName

    '        layerPPoint.Add(cpnode)

    '    Next




    '    'Case "pline" '线源

    '    Dim layerLine As New Layer("linesource")

    '    layerLine.desc = "线源."
    '    layerLine.AmbientColor = Color.Blue

    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerLine)


    '    For i As Integer = 0 To m_proj.TempAermod.Source.LineSources.ArrayLineSources.Length - 1




    '        '声明一个数组啊

    '        Dim dps(m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints.Length - 1) As DPoint

    '        Dim x, y As Double

    '        For j As Integer = 0 To m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints.Length - 1

    '            x = Me.GetXAbs(m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).x)

    '            y = Me.GetYAbs(m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).LinePoints(j).y)



    '            '关于数组，哈哈
    '            Dim dp As New DPoint(x, y)

    '            dps(j) = dp


    '        Next

    '        Dim w As Double = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).Width

    '        '半径，和高度，都没有定义哇

    '        Dim pl As New CPTubeLine(ti, w, 8, dps)

    '        Dim tln As New TubeLineNode(pl, m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).Location.Srcid)
    '        tln.desc = m_proj.TempAermod.Source.LineSources.ArrayLineSources(i).SourceName

    '        layerLine.Add(tln)






    '    Next



    '    'Case "poly" '多边形

    '    Dim layerPoly As New Layer("polysource")
    '    layerPoly.desc = "多边形源"


    '    layerPoly.AmbientColor = Color.Blue




    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerPoly)


    '    For i As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource.Length - 1


    '        '彻底崩溃，第一个点存的是相对坐标，其余点存的是绝对坐标，还有的都存了，有的没有存，让我彻底失败！


    '        Dim dps(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length) As DPoint

    '        Dim dp1 As New DPoint(Me.GetXAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Xs), Me.GetYAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Ys))
    '        dps(0) = dp1


    '        Dim x, y As Double

    '        For j As Integer = 0 To m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts.Length - 1

    '            x = Me.GetXAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).X)

    '            y = Me.GetYAbs(m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).GetVerts(j).Y)



    '            '关于数组，哈哈
    '            Dim dp As New DPoint(x, y)

    '            dps(j + 1) = dp



    '        Next



    '        Dim ply As New CPPoly(ti, 1, dps)
    '        Dim plyNode As New PolygonNode(ply, m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).Location.Srcid)
    '        plyNode.desc = m_proj.TempAermod.Source.AreaPolySources.AreaPolySource(i).SourceName

    '        layerPoly.Add(plyNode)


    '    Next

    '    'Case "cube" '体源

    '    Dim layerCube As New Layer("cubesource")
    '    layerCube.desc = "体源"
    '    layerCube.AmbientColor = Color.Blue



    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerCube)


    '    For i As Integer = 0 To m_proj.TempAermod.Source.VolumeSources.VolumeSource.Length - 1




    '        Dim ps As CAermod.VolumeSources

    '        ps = m_proj.TempAermod.Source.VolumeSources

    '        Dim x, y, dx, dy, dz As Double

    '        x = Me.GetXAbs(ps.VolumeSource(i).Location.Xs)
    '        y = Me.GetYAbs(ps.VolumeSource(i).Location.Ys)


    '        dx = ps.VolumeSource(i).Width
    '        dy = ps.VolumeSource(i).Width
    '        dz = ps.VolumeSource(i).Height



    '        Dim cube As New CPCube(ti, x, y, dx, dy, dz)
    '        Dim cubeNode As New CubeNode(cube, m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).Location.Srcid)
    '        cubeNode.desc = m_proj.TempAermod.Source.VolumeSources.VolumeSource(i).SourceName


    '        layerCube.Add(cubeNode)


    '    Next



    '    'Case "circle" '圆形面源

    '    Dim layerCircle As New Layer("circlesource")
    '    layerCircle.desc = "圆形面源"
    '    layerCircle.AmbientColor = Color.Blue


    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerCircle)


    '    For i As Integer = 0 To m_proj.TempAermod.Source.AreacircSources.AreaCircSource.Length - 1


    '        Dim x, y, r, h
    '        x = Me.GetXAbs(m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Xs)
    '        y = Me.GetYAbs(m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Ys)

    '        r = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Radius



    '        ' h = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Relhgt '这里暂时理解面是没有高度的
    '        h = 1


    '        Dim cylinder As New CPCylinder(ti, x, y, r, h)
    '        Dim cylinderNode As New CylinderNode(cylinder, m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).Location.Srcid)
    '        cylinderNode.desc = m_proj.TempAermod.Source.AreacircSources.AreaCircSource(i).SourceName

    '        layerCircle.Add(cylinderNode)

    '    Next




    '    'Case "rect" '矩形面源

    '    Dim layerRect As New Layer("rectsource")
    '    layerRect.desc = "矩形面源"
    '    layerRect.AmbientColor = Color.Blue


    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerRect)


    '    For i As Integer = 0 To AermodProject0.Aermod.Source.AreaSources.AreaSource.Length - 1



    '        ''设置第一个点
    '        'Dim ptA(3) As MapWinGIS.Point
    '        'ptA(0) = New MapWinGIS.Point
    '        'ptA(0).x = Me.GetUtmFromRelative(AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Xs, AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Ys).x
    '        'ptA(0).y = Me.GetUtmFromRelative(AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Xs, AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Location.Ys).y
    '        ''设置第2个点
    '        'ptA(1) = New MapWinGIS.Point
    '        'ptA(1).y = ptA(0).y + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Yinit * Math.Sin((90 - AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
    '        'ptA(1).x = ptA(0).x + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Yinit * Math.Cos((90 - AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
    '        ''设置第4个点
    '        'ptA(3) = New MapWinGIS.Point
    '        'ptA(3).y = ptA(0).y + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Xinit * Math.Sin(-AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)
    '        'ptA(3).x = ptA(0).x + AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Xinit * Math.Cos(-AermodProject0.Aermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)

    '        ''设置第3个点
    '        'ptA(2) = New MapWinGIS.Point
    '        'ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
    '        'ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x
    '        'fe.ptlist = ptA

    '        Dim temp As Double = m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys

    '        Dim dps(3) As DPoint

    '        dps(0) = New DPoint(Me.GetXAbs(m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Xs), Me.GetYAbs(m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Ys))

    '        dps(1) = New DPoint()
    '        dps(1).y = dps(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)
    '        dps(1).x = dps(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle) * Math.PI / 180)



    '        dps(3) = New DPoint()
    '        dps(3).y = dps(0).y + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)
    '        dps(3).x = dps(0).x + m_proj.TempAermod.Source.AreaSources.AreaSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.AreaSources.AreaSource(i).Angle * Math.PI / 180)


    '        dps(2) = New DPoint()
    '        dps(2).y = (dps(1).y - dps(0).y) + dps(3).y
    '        dps(2).x = (dps(1).x - dps(0).x) + dps(3).x



    '        '我真杯具啊,他咋就出不来咧

    '        'dps(4) = New DPoint()
    '        'dps(4).x = dps(0).x
    '        'dps(4).y = dps(0).y





    '        Dim rect As New CPPoly(ti, 1, dps)
    '        Dim rectNode As New PolygonNode(rect, m_proj.TempAermod.Source.AreaSources.AreaSource(i).Location.Srcid)
    '        rectNode.desc = m_proj.TempAermod.Source.AreaSources.AreaSource(i).SourceName


    '        layerRect.Add(rectNode)


    '    Next




    '    'Case "exp" '敞口源

    '    Dim layerExp As New Layer("expsource")
    '    layerExp.desc = "敞口源"
    '    layerExp.AmbientColor = Color.Blue


    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerExp)

    '    For i As Integer = 0 To m_proj.TempAermod.Source.OpenPitSources.OpenPitSource.Length - 1




    '        'fe.desc = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).SourceName
    '        'fe.sn = AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid
    '        ''设置第一个点
    '        'Dim ptA(3) As MapWinGIS.Point
    '        'ptA(0) = New MapWinGIS.Point
    '        'ptA(0).x = Me.GetUtmFromRelative(AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs, AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys).x
    '        'ptA(0).y = Me.GetUtmFromRelative(AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs, AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys).y
    '        ''设置第2个点
    '        'ptA(1) = New MapWinGIS.Point
    '        'ptA(1).y = ptA(0).y + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Sin((90 - AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
    '        'ptA(1).x = ptA(0).x + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Cos((90 - AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
    '        ''设置第4个点
    '        'ptA(3) = New MapWinGIS.Point
    '        'ptA(3).y = ptA(0).y + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Sin(-AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)
    '        'ptA(3).x = ptA(0).x + AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Cos(-AermodProject0.Aermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)

    '        ''设置第3个点
    '        'ptA(2) = New MapWinGIS.Point
    '        'ptA(2).y = (ptA(1).y - ptA(0).y) + ptA(3).y
    '        'ptA(2).x = (ptA(1).x - ptA(0).x) + ptA(3).x



    '        Dim dps(3) As DPoint

    '        dps(0) = New DPoint(Me.GetXAbs(m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Xs), Me.GetYAbs(m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Ys))

    '        dps(1) = New DPoint()
    '        dps(1).x = dps(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Cos((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)
    '        dps(1).y = dps(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Yinit * Math.Sin((90 - m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle) * Math.PI / 180)

    '        dps(3) = New DPoint()
    '        dps(3).y = dps(0).y + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Sin(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)
    '        dps(3).x = dps(0).x + m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Xinit * Math.Cos(-m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Angle * Math.PI / 180)

    '        dps(2) = New DPoint()
    '        dps(2).y = (dps(1).y - dps(0).y) + dps(3).y
    '        dps(2).x = (dps(1).x - dps(0).x) + dps(3).x




    '        ' Dim h As Double = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Relhgt
    '        Dim h As Double = 1




    '        Dim rect As New CPPoly(ti, h, dps)
    '        Dim rectNode As New PolygonNode(rect, m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).Location.Srcid)
    '        rectNode.desc = m_proj.TempAermod.Source.OpenPitSources.OpenPitSource(i).SourceName

    '        layerExp.Add(rectNode)




    '    Next


    '    'Case "build" '建筑物


    '    Dim layerBuild As New Layer("building")

    '    layerBuild.desc = "建筑物"
    '    layerBuild.AmbientColor = Color.Blue


    '    FuEngine.GetEngine.GetScene("terrainscene").AddNode(layerBuild)


    '    For i As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi.Length - 1


    '        'fe.desc = AermodProject0.Aermod.Bprm.ArryBldgi(i).BuildName
    '        'fe.sn = AermodProject0.Aermod.Bprm.ArryBldgi(i).BuildStack
    '        ''设置第一个点
    '        'Dim ptA(AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1) As MapWinGIS.Point
    '        'For j As Integer = 0 To AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1
    '        '    ptA(j) = New MapWinGIS.Point
    '        '    ptA(j).x = Me.GetUtmFromRelative(AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x, AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y).x
    '        '    ptA(j).y = Me.GetUtmFromRelative(AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x, AermodProject0.Aermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y).y

    '        'Next



    '        Dim dps(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1) As DPoint

    '        For j As Integer = 0 To m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner.Length - 1

    '            Dim dp As New DPoint()

    '            dp.x = Me.GetXAbs(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).x)
    '            dp.y = Me.GetYAbs(m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).ArryBuilCorner(j).y)

    '            dps(j) = dp

    '        Next

    '        Dim h As Double = m_proj.TempAermod.Bprm.ArryBldgi(i).ArryBuildTire(0).TireHight
    '        Dim hg As Double = 0

    '        Dim build As New CPPoly(ti, h, dps, hg)
    '        Dim buildNode As New PolygonNode(build, m_proj.TempAermod.Bprm.ArryBldgi(i).BuildStack)
    '        buildNode.desc = m_proj.TempAermod.Bprm.ArryBldgi(i).BuildName


    '        layerBuild.Add(buildNode)


    '    Next








    'End Sub



    Public Function SaveCurrentContour(ByVal myfilename As String) As Boolean

        If Not m_Ready Then

            Return False

        End If


        Dim cn As ConcentrationNodeV3 = Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").GetNode("concentration")

        Dim cons As Contours = cn.MyContours




        '文件的删除逻辑

        If File.Exists(myfilename) Then
            Try
                File.SetAttributes(myfilename, FileAttributes.Normal)
                File.Delete(myfilename)

            Catch ex As Exception

                MessageBox.Show("删除旧文件失败 ！ " + myfilename + "  " + ex.Message)

                Return False
            End Try



        End If

        Dim formatter As New BinaryFormatter()
        Dim stream As Stream = New FileStream(myfilename, FileMode.Create, FileAccess.Write, FileShare.None)


        formatter.Serialize(stream, cons)
        stream.Close()


        Return True



    End Function

    Public Function LoadContourToCurrent(ByVal myfilename As String) As Boolean


        If Not m_Ready Then

            Return False

        End If


        If Not System.IO.File.Exists(myfilename) Then

            MessageBox.Show("加载文件失败！未找到存储的文件！" + myfilename.ToString())

            Return False

        End If

        Dim formatter As IFormatter = New BinaryFormatter()

        Dim stream As Stream = New FileStream(myfilename, FileMode.Open, FileAccess.Read, FileShare.None)


        Dim cons As Contours


        cons = formatter.Deserialize(stream)

        stream.Close()

        '王如建增加的代码----------------
        cons.ReSetContoursRegion()
        '-----------------
        '王如建增加的代码----------------
        ContourPaintForm1.ContourPaintSetting.ContourPannel.Contours = cons
        ContourPaintForm1.SetActivePaintForm()
        ContourPaintForm1.ContourPaintSetting.SetGrid(cons.Xmin, (cons.Xmax - cons.Xmin) / (cons.nCol - 1), cons.nCol, cons.Ymin, (cons.Ymax - cons.Ymin) / (cons.nRow - 1), cons.nRow, cons.GridPoint)
        '给环境赋予相应的变量
        Dim tn As ConcentrationNodeV3 = Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").GetNode("concentration")

        '-----------------

        tn.MyContours = cons

        Return True




    End Function



    Dim strGridName As String
    Dim oldKey As String = ""

    Dim fPath As String = "c:\"

    Public Sub SetProjPath(ByVal str As String)

        '如果前面已经打开过，里面有东西,就先保存

        If m_Ready Then

            If Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene") IsNot Nothing Then



                Dim nameProj As String = fPath + "vtk.fzh"
                Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").SaveSceneBinary(nameProj)

            End If

           

        End If


        fPath = str + "\" + "vtk" + "\"

        If Not System.IO.Directory.Exists(fPath) Then

            System.IO.Directory.CreateDirectory(fPath)


        End If


    End Sub

    Protected Function GetGridNameFromKey(ByVal strkey As String)

        Dim str() As String = strkey.Split("_")
        Return str(0)

    End Function


    Dim bHoursValue As Boolean = False

    Public Sub ChangeContour(ByVal contours As Contours, ByVal xPre As Double, ByVal yPre As Double, ByVal strKey As String, ByVal IsSave As Boolean)




        'Dim cn As ConcentrationNodeV3 = Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").GetNode("concentration")



        'cn.ChangeTextureCoord(contours.Xmin + xPre, contours.Ymin + yPre, contours.Xmax + xPre, contours.Ymax + yPre)





        ''更新等值线
        'cn.MyContours = contours




        ContourPaintForm1.ContourPaintSetting.ContourPannel.Contours = contours

        ContourPaintForm1.SetActivePaintForm()
        ContourPaintForm1.ContourPaintSetting.SetGrid(contours.Xmin, (contours.Xmax - contours.Xmin) / (contours.nCol - 1), contours.nCol, contours.Ymin, (contours.Ymax - contours.Ymin) / (contours.nRow - 1), contours.nRow, contours.GridPoint)


        '首先判断旧有的文件时候需要保存
        If Not bHoursValue And oldKey <> "" Then

            Me.SaveCurrentContour(fPath & oldKey)

        End If

        oldKey = strKey

        Dim bExistValue As Boolean = System.IO.File.Exists(fPath & strKey)  '是否是已经保存的值


        Dim newGridName As String = Me.GetGridNameFromKey(strKey)
        If Not IsSave Then


            '这里不需要保存等值线的属性，因为个数太多


            Dim tn As ConcentrationNodeV3 = Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").GetNode("concentration")


            'If strGridName = newGridName Then
            '    '不需要改变污染图大小

            'Else

            '更新网格位置变化,这个值是相对坐标，你还需要绝对坐标转换，来使网格位置更新正确
            tn.ChangeTextureCoord(contours.Xmin + xPre, contours.Ymin + yPre, contours.Xmax + xPre, contours.Ymax + yPre)
            strGridName = newGridName

            'End If


            '更新等值线
            tn.MyContours = contours





        Else



            '任何情况都要注意网格范围的变化

            Dim tn As ConcentrationNodeV3 = Fu3DEngine.FuEngine.GetEngine().GetScene("terrainscene").GetNode("concentration")

            '更新网格位置变化,这个值是相对坐标，你还需要绝对坐标转换，来使网格位置更新正确
            tn.ChangeTextureCoord(contours.Xmin + xPre, contours.Ymin + yPre, contours.Xmax + xPre, contours.Ymax + yPre)



            '查看是否已经有对应的等值线文件
            If bExistValue Then

                Me.LoadContourToCurrent(fPath & strKey)
                strGridName = Me.GetGridNameFromKey(strKey)



            Else


                strGridName = newGridName


                'End If


                '更新等值线
                tn.MyContours = contours



            End If


            '加载以有的文件



        End If



        '在外围建立一个contours管理器，那样你就可以玩无限等值线啦






        'tn.ChangeGridPos()








    End Sub






    Private Sub frmVtkRender_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed







    End Sub


End Class